package com.klw.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.klw.business.domain.KlmBatchModel;
import com.klw.business.service.IKlwMlFeaturesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.klw.common.annotation.Log;
import com.klw.common.core.controller.BaseController;
import com.klw.common.core.domain.AjaxResult;
import com.klw.common.enums.BusinessType;
import com.klw.business.domain.KlwStudents;
import com.klw.business.service.IKlwStudentsService;
import com.klw.common.utils.poi.ExcelUtil;
import com.klw.common.core.page.TableDataInfo;

/**
 * 学生Controller
 * 
 * @author klw
 * @date 2025-08-24
 */
@RestController
@RequestMapping("/core/students")
public class KlwStudentsController extends BaseController
{
    @Autowired
    private IKlwStudentsService klwStudentsService;

    @Autowired
    private IKlwMlFeaturesService klwMlFeaturesService;

    /**
     * 查询学生列表
     */
    @PreAuthorize("@ss.hasPermi('core:students:list')")
    @GetMapping("/list")
    public TableDataInfo list(KlwStudents klwStudents)
    {
        startPage();
        List<KlwStudents> list = klwStudentsService.selectKlwStudentsList(klwStudents);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @PreAuthorize("@ss.hasPermi('core:students:export')")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KlwStudents klwStudents)
    {
        List<KlwStudents> list = klwStudentsService.selectKlwStudentsList(klwStudents);
        ExcelUtil<KlwStudents> util = new ExcelUtil<KlwStudents>(KlwStudents.class);
        util.exportExcel(response, list, "学生数据");
    }

    /**
     * 获取学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('core:students:query')")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(klwStudentsService.selectKlwStudentsByStudentId(studentId));
    }

    /**
     * 新增学生
     */
    @PreAuthorize("@ss.hasPermi('core:students:add')")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KlwStudents klwStudents)
    {
        return toAjax(klwStudentsService.insertKlwStudents(klwStudents));
    }

    /**
     * 修改学生
     */
    @PreAuthorize("@ss.hasPermi('core:students:edit')")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KlwStudents klwStudents)
    {
        return toAjax(klwStudentsService.updateKlwStudents(klwStudents));
    }

    /**
     * 删除学生
     */
    @PreAuthorize("@ss.hasPermi('core:students:remove')")
    @Log(title = "学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable String[] studentIds)
    {
        return toAjax(klwStudentsService.deleteKlwStudentsByStudentIds(studentIds));
    }

    /**
     * 生成学生特征数据
     */
    @PostMapping("/generateFeaturesData")
    public AjaxResult generateFeaturesData(@RequestBody KlmBatchModel klmBatchModel) {
        return toAjax(klwMlFeaturesService.generateFeatursDataSingle(klmBatchModel));
    }

    /**
     * 批量生成学生特征数据
     */
    @PostMapping("/generateFeaturesDataBatch")
    public AjaxResult generateFeaturesDataBatch(@RequestBody KlmBatchModel klmBatchModel) {
        return toAjax(klwMlFeaturesService.generateFeatursDataBatch(klmBatchModel.getList()));
    }

    @PostMapping("/predictSingle")
    public AjaxResult predictSingle(@RequestBody KlmBatchModel klmBatchModel) throws Exception {
        klwStudentsService.predictSingle(klmBatchModel);
        return success();
    }

    @PostMapping(value = "/predictBatch")
    public AjaxResult predictBatch(@RequestBody KlmBatchModel klmBatchModel) throws Exception{
        klwStudentsService.predicBatch(klmBatchModel);
        return success();
    }
}
